const match_id = "match.bro.official.pc-2018-07.steam.squad-fpp.sa.2020.06.06.11.7017ba54-bc2a-4bc9-a0d8-8cf250959c31";
const mongoConnected = require("../lib/mongoose_connect");
const mongoModels = require("../lib/mongoose_schemas");
const lodash = require("lodash");
const fs = require("fs-extra");
const path = require("path");

mongoConnected.then(async $ => {
  let gameStateEvents = (await mongoModels.Event.find({
    _T: "LogGameStatePeriodic",
    match_id: match_id
  })).map(e => e._doc).sort((a, b) => a._D.valueOf() - b._D.valueOf());
  let filtered = gameStateEvents.filter(e => {
    let isGame = e.common.isGame;
    return isGame % 0.5 == 0;
    let int = parseInt(isGame);
    return int && int === isGame;
  });
  debugger
  let safetyZoneInfos = filtered.map(e => {
    return {
      safetyZoneRadius: e.gameState.safetyZoneRadius,
      safetyZonePosition: e.gameState.safetyZonePosition
    }
  });
  safetyZoneInfos = lodash.uniqWith(safetyZoneInfos, lodash.isEqual);
  await fs.writeFile(path.join(__dirname, "../test/210219LogGameStatePeriodic.json"), JSON.stringify(filtered));
  debugger
})